package com.bgs.microservices.service.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @ClassName SpringDoc
 * @Description SpringDoc 配置文档
 * @Author 17179
 * @Date 2023/8/2 15:46
 * http://localhost:11001/doc.html 美化的接口文档系统
 **/
@EnableKnife4j
@Configuration
public class SpringDocConfig {
    @Bean
    public OpenAPI springDocOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("微服务接口平台")
                        .description("提供各种接口数据")
                        .version("v1.0.0")
                        .license(new License()
                                .name("Licence Version 1.0")
                                .url("#"))
                        .contact(new Contact()
                                .name("zcy")
                                .email("171794688@qq.com"))).security(List.of(new SecurityRequirement().addList("api_token")));
    }

//    @Value(value = "${server.port:8080}")
//    private int port;
//
//    @Bean
//    public OpenAPI springShopOpenApi() {
//        final String loginToken = "Authorization";
//        return new OpenAPI().info(new Info().title("API")
//                        .description("Sky网关")
//                        .version("v1.0.0")).externalDocs(new ExternalDocumentation()
//                        .description("Sky网关")
//                        .url("http://127.0.0.1:" + port))
//                .components(new Components().addSecuritySchemes(loginToken, new SecurityScheme()
//                        .type(SecurityScheme.Type.HTTP).scheme("ZY_").bearerFormat("JWT")
//                        .in(SecurityScheme.In.HEADER)
//                        .name(loginToken)))
//                .addSecurityItem(new SecurityRequirement().addList(loginToken));
//    }
//
//    @Bean
//    public GroupedOpenApi service2Api() {
//        String[] paths = {"/_default/**"};
//        return GroupedOpenApi.builder().group("_default")
//                .pathsToMatch(paths)
//                .build();
//    }
}
